package com.example.weiba_app;

import java.util.List;

import com.example.domain.AppUser;
import com.example.domain.User;
import com.example.httputil.GetLoginJson;
import com.example.httputil.httpGetInputStream;

import android.R.integer;
import android.R.string;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.SpannableString;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.view.View.OnClickListener;

public class Login extends Activity {
	List<User> userlist;
	private Button logBtn;
	private Button resetBtn;
	private EditText uname;
	private EditText psw;
	private TextView toreg;
	String username = "";
	String password = "";
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.login);
		logBtn = (Button) findViewById(R.id.login);
		resetBtn = (Button) findViewById(R.id.reset);
		uname = (EditText)  findViewById(R.id.unameEt);
		psw = (EditText)  findViewById(R.id.pswEt);
		toreg = (TextView) findViewById(R.id.toreg);
		

		
		logBtn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				try {
					username = uname.getText().toString();
					password = psw.getText().toString();
					userlist=GetLoginJson.getJsonUserList(httpGetInputStream.getLoginInputStream(username, password));
					if(userlist.get(0).getUserName()!=null){
						logBtn.setText(userlist.get(0).getUserName());
					}
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		});
		toreg.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				Intent intent = new Intent(Login.this, Regist.class);
				startActivity(intent);
				
			}
		});
		
		
	}
	
}
